#!/bin/bash
#close firewalld and selinux
#centos6 close firewalld
#service iptables stop
#centos7
setenforce 0&>/dev/null
systemctl stop firewalld&>/dev/null
#centos6 close selinux
#chkconfig iptables off
#centos7
sed -ir 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
echo "防火墙和selinux关闭完成"
#firewall and selinux close
#测试网络
ping -c1 www.baidu.com&>/dev/null
if [ $? -eq 0 ]
then
    echo "网络正常"
else
    echo "请检查网络" && exit
fi
#配置yum源
mkdir /etc/yum.repos.d/repo&>/dev/null
mv /etc/yum.repos.d/* /etc/yum.repos.d/repo&>/dev/null
echo "[base]" > /etc/yum.repos.d/aliyun.repo
echo "name=aliyun base" >> /etc/yum.repos.d/aliyun.repo
echo "baseurl=https://mirrors.aliyun.com/centos/7/os/x86_64/" >> /etc/yum.repos.d/aliyun.repo
echo "gpgcheck=0" >> /etc/yum.repos.d/aliyun.repo
echo "enabled=1" >> /etc/yum.repos.d/aliyun.repo
echo "[epel]" > /etc/yum.repos.d/aliyun.repo
echo "name=aliyun epel" >> /etc/yum.repos.d/aliyun.repo
echo "baseurl=https://mirrors.aliyun.com/epel/7/x86_64/" >> /etc/yum.repos.d/aliyun.repo
echo "gpgcheck=0" >> /etc/yum.repos.d/aliyun.repo
echo "enabled=1" >> /etc/yum.repos.d/aliyun.repo
#nfs服务 服务器端和客户端都要安装!!!!
yum -y install nfs-utils rpcbind&>/dev/null && echo "软件安装完成"
#配置共享空间 添加新硬盘!!!!!!
parted /dev/sdb mklabel gpt&>/dev/null
parted /dev/sdb mkpart primary 1 3G&>/dev/null
mkfs.xfs /dev/sdb1&>/dev/null
#发布共享目录
read -p "input your share dir: " dir
[ ! -d $dir ] && mkdir -p $dir
#授权
chmod o+t $dir
echo "/dev/sdb1 /$dir xfs defaults 0 0" > /etc/fstab
mount -a
read -p "input your share host(192.168.*.0/24(rw)): " host
cat /etc/exports <<eof
/$dir $host(rw,sync,no_root_squash)
eof
#启动服务,开机自启动
#service rpcbind restart&>/dev/null && echo "rpcbind服务启动"
#service nfs restart&>/dev/null && echo "nfs服务启动成功"
#chkconfig rpcbind on
#chkconfig nfs on
systemctl start nfs
echo "nfs服务启动完成"
#测试验证
#mkdir /$dir &>/dev/null
#mount.nfs localhost:$dir /$dir
#[ $? -eq 0 ] && echo "nfs服务测试ok,可以正常使用"
#umount /$dir
showmount -e $host